/**
 * 
 */
package pacMan;

/**
 * 
 * Class: ScoreTracker
 * Manages the tally of points earned by the player in this game, and the
 * highest amount scored in any game.
 *
 * @author Tomas Rivera
 * @version $Id$
 */
public class ScoreTracker {
	
	public static final int POINT_VALUE_EXTRA_LIFE_EARNED = 10000;
	
	// Point values for consumable objects.
	public static final int PELLET_POINT_VALUE = 10;
	public static final int ENERGIZER_POINT_VALUE = 50;
	public static final int GHOST_POINT_VALUE = 200;
	public static final int CHERRIES_PV = 100;
	public static final int STRAWBERRY_PV = 300;
	public static final int PEACH_PV = 500;
	public static final int APPLE_PV = 700;
	public static final int GRAPES_PV = 1000;
	public static final int GALAXIAN_PV = 2000;
	public static final int BELL_PV = 3000;
	public static final int KEY_PV = 5000;

	//////////////////////////////////////////////////////////
	// Constructor methods
	//////////////////////////////////////////////////////////
	
	/**
	 * 
	 * @param currentScore
	 * @param highScore
	 */
	public ScoreTracker(int currentScore, int highScore) {
		this.currentScore = currentScore;
		this.highScore = highScore;
		extraLifeEarned = false;
	}
	
	//////////////////////////////////////////////////////////
	// Public / Protected methods
	//////////////////////////////////////////////////////////
	
	/**
	 * Increments the current score by the value passed. When the
	 * current score exceeds the high score, the high score will
	 * be set equal to the current score. When current score exceeds
	 * specified threshold, this will return TRUE to indicate the
	 * player has earned an extra life.
	 * 
	 * @param value
	 * @return
	 */
	public boolean addToScore(int value) {
		currentScore += value;
		if(currentScore > highScore) {
			highScore = currentScore;
		}
		
		if(!extraLifeEarned && currentScore >= POINT_VALUE_EXTRA_LIFE_EARNED) {
			// Extra life! We only get one of these per game.
			extraLifeEarned = true;
			SoundEffect.EVENT_PACMAN_EXTRALIFE.play();
			return true;
		}
		
		return false;
	}
	
	/**
	 * Clears the current player score.
	 */
	public void resetScore() { 
		currentScore = 0;
		extraLifeEarned = false;
	}
	
	/**
	 * Returns the score for the current game or last active game.
	 * @return
	 */
	public int getCurrentScore() { return currentScore; }
	
	/**
	 * Returns the high score out of all games played.
	 * @return
	 */
	public int getHighScore() { return highScore; }
	
	//////////////////////////////////////////////////////////
	// Private member variables
	//////////////////////////////////////////////////////////
	
	private int currentScore;
	private int highScore;
	private boolean extraLifeEarned;

}

// TODO: This should know where to draw itself.
